home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / DTS QT Utilities.Aug-95 / Projects & Test Apps / QT Internals / QTInternals.c < prev    next >
Encoding:
Text File  |  1995-05-24  |  13.3 KB  |  405 lines  |  [TEXT/MPCC]

  1. /*
  2.     File:        QTInternals.c
  3.  
  4.     Contains:    Functions dealing with dumping internal movie information.
  5.  
  6.     Written by:    DTS
  7.  
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.        <1>         1/4/95    khs        first file
  13.        
  14. */
  15.  
  16.  
  17. // INCLUDES
  18. #include "QTInternals.h"
  19. #include "DTSQTUtilities.h"
  20.  
  21.  
  22. // ______________________________________________________________________
  23. // FUNCTIONS
  24.  
  25.  
  26.  
  27. // ______________________________________________________________________
  28. void ShowGlobalMovieInfo(Movie theMovie)
  29. {
  30.     OSErr        anErr = noErr;
  31.     Str255     tmpStr;
  32.     TimeValue    tv, ts;
  33.     Fixed         mr;
  34.     long             movieSize = 0L;
  35.     
  36.     DebugAssert(aMovie != NULL);
  37.     
  38.     GetWTitle(FrontWindow(), tmpStr);
  39.     printf("\nGlobal System Information for %s:\n", p2cstr(tmpStr));
  40.  
  41.     // Memory related information.
  42.     anErr = QTUCalculateMovieMemorySize(theMovie, &movieSize);
  43.     if(anErr == noErr) 
  44.     {
  45.         printf("This movie allocates %ld bytes in the current application heap.\n", movieSize);
  46.         printf("Note that any possible associated movie controllers take each 10k or so.\n\n");
  47.     }
  48.     
  49.     // Global Time Information
  50.     ts = GetMovieTimeScale(theMovie);
  51.     tv = GetMovieDuration(theMovie);
  52.     printf("The time scale for this movie is %ld.\n", ts);
  53.     printf("The movie duration (TimeValue) = %ld\n", tv);
  54.     printf("The movie duration in seconds = %7.2f\n", (float)  tv / ts);
  55.     
  56.     printf("The current movie position (in seconds) = %7.2f\n", (float) GetMovieTime(theMovie, NULL) / ts);
  57.  
  58.     mr = GetMovieRate(theMovie);
  59.     printf("The current movie rate is %7.2f  (0 means movie is not running, < 0 going backwards).\n",  (float) mr /fixed1);
  60. }
  61.  
  62.  
  63. // ______________________________________________________________________
  64. void ShowMovieTrackInfo(Movie theMovie)
  65. {
  66.     OSErr                    anErr  = noErr;
  67.     long                        aTrackCount, index;
  68.     Track                    aTrack;
  69.     long                        aTrackUsage;
  70.     Str255                    tmpStr;
  71.     Fixed                    height, width;
  72.     short                    trackVol;
  73.     MatrixRecord        mr;
  74.     long                        nVideoTracks = 0;
  75.     long                        nSoundTracks = 0;
  76.     long                        nTextTracks = 0;
  77.     long                        nMusicTracks = 0;
  78.     
  79.     GetWTitle(FrontWindow(), tmpStr);
  80.     printf("\nTrack Information for %s:\n", p2cstr(tmpStr));
  81.     
  82.     // TRACK COUNT
  83.     aTrackCount = GetMovieTrackCount(theMovie);
  84.     anErr = GetMoviesError(); DebugAssert(anErr == noErr);
  85.     if(anErr != noErr) return;
  86.     
  87.     if(aTrackCount == 0) 
  88.     {
  89.         printf("The Movie has no tracks.\n");
  90.         return;
  91.     }
  92.     else
  93.         printf("The Movie has %d track(s).\n", aTrackCount);
  94.  
  95.     // Parse through each track and get more information:
  96.     for(index = 1; index <= aTrackCount; index++)
  97.     {
  98.         OSType aTrackType;
  99.         Media aMedia;
  100.         
  101.         printf("\n");
  102.         
  103.         aTrack = GetMovieIndTrack(theMovie, index);
  104.         
  105.         // TRACK TYPE
  106.         aMedia = GetTrackMedia(aTrack);
  107.         GetMediaHandlerDescription(aMedia, &aTrackType, 0, 0);
  108.         
  109.         switch (aTrackType)
  110.         {
  111.             case SoundMediaType: printf("This is a sound track.\n"); 
  112.                 nSoundTracks++;
  113.                 break;
  114.                 
  115.             case VideoMediaType: printf("This is a video track.\n"); 
  116.                 nVideoTracks++;
  117.                 break;
  118.                 
  119.             case TextMediaType: printf("This is a text track.\n"); 
  120.                 nTextTracks++;
  121.                 break;
  122.                 
  123.             case MPEGMediaType: printf("This is an MPEG track.\n"); 
  124.                 break;
  125.                 
  126.             case MusicMediaType: printf("This is a music track.\n"); 
  127.                 nMusicTracks++;
  128.                 break;
  129.                 
  130.             case TimeCodeMediaType: printf("This is a time code track.\n"); 
  131.                 break;
  132.                 
  133.             default: 
  134.             {
  135.                 Byte *bp = (Byte *)&aTrackType;
  136.                 printf("The track is of type '%c%c%c%c' format.\n", bp[0], bp[1], bp[2], bp[3]);
  137.                 break;
  138.             }
  139.         }
  140.         
  141.         // TRACK ID
  142.         printf("Track ID: %d\n", GetTrackID(aTrack));
  143.     
  144.         // TRACK ENABLED
  145.         if(GetTrackEnabled(aTrack))
  146.             printf("Track is enabled.\n");
  147.         else
  148.             printf("Track is disabled.\n");
  149.         
  150.         // TRACK LAYER
  151.         printf("Track Layer: %d\n", GetTrackLayer(aTrack));
  152.         
  153.         // TRACK USAGE
  154.         aTrackUsage = GetTrackUsage(aTrack);
  155.         if(aTrackUsage & trackUsageInMovie)
  156.             printf("Track is used in Movie.\n");
  157.         if(aTrackUsage & trackUsageInPreview)
  158.             printf("Track is used in a preview.\n");
  159.         if(aTrackUsage & trackUsageInPoster)
  160.             printf("Track is used in a poster.\n");
  161.     
  162.         // TRACK DURATION
  163.         printf("Duration of the track = %ld\n", GetTrackDuration(aTrack));
  164.         
  165.         // TRACK DIMENSIONS
  166.         GetTrackDimensions(aTrack, &width, &height);
  167.         printf("Track width = %ld, Track height = %ld\n", Fix2Long(width), Fix2Long(height));
  168.         
  169.         // TRACK MATRIX
  170.         GetTrackMatrix(aTrack, &mr);
  171.         
  172.         printf("Matrix record, row 0 = [%ld], [%ld], [%ld]\n", Fix2Long(*mr.matrix[0,0]), 
  173.                                 Fix2Long(*mr.matrix[0,1]), Fix2Long(*mr.matrix[0,2]));
  174.         printf("Matrix record, row 1 = [%ld], [%ld], [%ld]\n", Fix2Long(*mr.matrix[1,0]), 
  175.                                 Fix2Long(*mr.matrix[1,1]), Fix2Long(*mr.matrix[1,2]));
  176.         printf("Matrix record, row 2 = [%ld], [%ld], [%ld]\n", Fix2Long(*mr.matrix[2,0]), 
  177.                                 Fix2Long(*mr.matrix[2,1]), Fix2Long(*mr.matrix[2,2]));
  178.         
  179.         // TRACK VOLUME
  180.         trackVol = GetTrackVolume(aTrack);
  181.         if(trackVol == 255)
  182.             printf("Track Volume is 1.0\n");
  183.         else
  184.             printf("Track Volume = %d.%d\n", (signed short)(trackVol >> 8) , (trackVol & 0xFF));
  185.     }
  186.     
  187.     // Check how many similar tracks, if too many of same warn (crossplatform issues)
  188.     if(nVideoTracks > 1)
  189.         printf("NOTE! You have more than one video track (%ld tracks), this will be a problem with QuickTime for Windows.\n", nVideoTracks);
  190.  
  191.     if(nSoundTracks > 1)
  192.         printf("NOTE! You have more than one sound track (%ld tracks), you need to enable just one at a time under QuickTime for Windows (2.0.1 forward).\n", nSoundTracks);
  193.  
  194.     if(nTextTracks > 1)
  195.         printf("NOTE! You have more than one text track (%ld tracks), this will be a problem with QuickTime for Windows.\n", nTextTracks);
  196.  
  197.     if(nMusicTracks > 1)
  198.         printf("NOTE! You have more than one music track (%ld tracks), this will be a problem with QuickTime for Windows.\n", nMusicTracks);
  199. }
  200.  
  201.  
  202. // ______________________________________________________________________
  203. void ShowMovieVideoInfo(Movie theMovie)
  204. {
  205.     OSErr        anErr = noErr;
  206.     Str255     tmpStr;
  207.     short        trackCount, index;
  208.     long            nSamples;
  209.     float            nSeconds;
  210.  
  211.     DebugAssert(aMovie != NULL);
  212.     
  213.     GetWTitle(FrontWindow(), tmpStr);
  214.     printf("\nVideo Media Information for %s:\n", p2cstr(tmpStr));
  215.  
  216.     // VIDEO FRAMES/SAMPLES
  217.     nSamples = QTUCountMediaSamples(theMovie, VideoMediaType);
  218.     
  219.     printf("The movie has %ld video frames (samples) ", nSamples);
  220.     printf("of which %ld are key frames\n", QTUCountKeySamples(theMovie, VideoMediaType) );
  221.  
  222.     printf("The duration of the first video sample is %ld\n", QTUGetDurationOfFirstMovieSample(theMovie, VideoMediaType));
  223.     
  224.     nSeconds =     GetMovieDuration(theMovie)/ GetMovieTimeScale(theMovie);
  225.     printf("Frames per second (assuming that each video sample is of the same length) = %7.2f  fps\n", (float) nSamples/nSeconds );
  226.     
  227.     // Get the Image Description Structure and present the values.
  228.     trackCount = GetMovieTrackCount(theMovie);
  229.     
  230.     for(index = 1; index <= trackCount; index++)
  231.     {
  232.         Track        aTrack = NULL;
  233.         Media        aMedia = NULL;
  234.         OSType        aMediaType;
  235.         
  236.         aTrack = GetMovieIndTrack(theMovie, index); DebugAssert(aTrack != NULL);
  237.         aMedia = GetTrackMedia(aTrack); DebugAssert(aMedia != NULL);
  238.         anErr = GetMoviesError(); DebugAssert(anErr == noErr);
  239.         if(anErr != noErr)
  240.         {
  241.             printf("Problems with getting trackmedia = %d\n", anErr);
  242.             return;
  243.         }
  244.  
  245.         GetMediaHandlerDescription(aMedia, &aMediaType, 0, 0);
  246.         if(aMediaType == VideoMediaType) // We just want to check the video media samples.
  247.         {
  248.             SampleDescriptionHandle anImageDesc = NULL;
  249.             anImageDesc = (SampleDescriptionHandle)NewHandle(sizeof(SampleDescription));
  250.             DebugAssert(GetMemErr == noErr);
  251.  
  252.             GetMediaSampleDescription(aMedia, 1, anImageDesc);
  253.             anErr = GetMoviesError(); DebugAssert(anErr == noErr);
  254.             MoveHHi((Handle)anImageDesc); HLock((Handle)anImageDesc); // Really would not need to, but printf (don't trust that one
  255.                                                                                                           // due to the MetroWerks Sioux environment).
  256.             if(anErr != noErr)
  257.             {
  258.                 DisposeHandle((Handle)anImageDesc);
  259.                 continue;
  260.             }
  261.  
  262.             // OK, we have the Image Description, now present the values (see IM:QuickTime, page 3-50 for more
  263.             // information about the ImageDescription structure).
  264.             
  265.             printf("The video track has a pixel depth of %d.\n", (*(ImageDescriptionHandle)anImageDesc)->depth);
  266.     
  267.             // Get the image description height and width values, test if these are multiple of 4 (if not there's a performance penalty).
  268.             {
  269.             long rest;
  270.             
  271.             printf("The video track has a source image height of %d.\n", (*(ImageDescriptionHandle)anImageDesc)->height);
  272.         
  273.             rest  = (*(ImageDescriptionHandle)anImageDesc)->height % 4;
  274.             if (rest != 0)
  275.                 printf("NOTE! The source image height is not a multiple of 4, this means a performance hit.\n");
  276.  
  277.             printf("The video track has a source image width of %d.\n", (*(ImageDescriptionHandle)anImageDesc)->width);
  278.             
  279.             rest  = (*(ImageDescriptionHandle)anImageDesc)->width % 4;
  280.             if (rest != 0)
  281.                 printf("NOTE! The source image width is not a multiple of 4, this means a performance hit.\n");
  282.             }
  283.             
  284.             printf("The video track has a horizontal resolution of %ld.\n", Fix2Long( (*(ImageDescriptionHandle)anImageDesc)->hRes) );
  285.             printf("The video track has a vertical resolution of %ld.\n", Fix2Long( (*(ImageDescriptionHandle)anImageDesc)->vRes) );
  286.             
  287.             printf("The codec used to compress the video samples:  %s\n", p2cstr( (*(ImageDescriptionHandle)anImageDesc)->name) );
  288.             printf("Note that this is the codec for the first video sample, the video samples in the movie might have various codecs used...\n");
  289.             {
  290.                 Byte *bp = (Byte *)&(*(ImageDescriptionHandle)anImageDesc)->vendor;
  291.                 printf("The video track was compressed by codec provided by '%c%c%c%c'.\n", bp[0], bp[1], bp[2], bp[3]);
  292.             }
  293.             printf("The temporal compression setting is %ld\n",  (*(ImageDescriptionHandle)anImageDesc)->temporalQuality);
  294.             printf("The spatial compression setting is %ld\n",  (*(ImageDescriptionHandle)anImageDesc)->spatialQuality);
  295.             
  296.             
  297.             printf("The image description structure is %ld bytes in size.\n", 
  298.                             (*(ImageDescriptionHandle)anImageDesc)->idSize);
  299.  
  300.             DisposeHandle((Handle)anImageDesc);
  301.         }
  302.     }
  303. }
  304.  
  305.  
  306. // ______________________________________________________________________
  307. void ShowMovieSoundInfo(Movie theMovie)
  308. {
  309.     Str255     tmpStr;
  310.     short        trackCount, index;
  311.     OSErr        anErr = noErr;
  312.     
  313.     DebugAssert(aMovie != NULL);
  314.     
  315.     GetWTitle(FrontWindow(), tmpStr);
  316.     printf("\nSound Media Information for %s:\n", p2cstr(tmpStr));
  317.     
  318. #ifdef THIS_WILL_TAKE_LONG
  319.     printf("The movie has %d sound samples (samples)\n", QTUCountMediaSamples(theMovie, SoundMediaType));
  320. #endif // THIS_WILL_TAKE_LONG
  321.  
  322.     // Get the sound description handle and munch it:
  323.     trackCount = GetMovieTrackCount(theMovie);
  324.     
  325.     for(index = 1; index <= trackCount; index++)
  326.     {
  327.         Track        aTrack = NULL;
  328.         Media        aMedia = NULL;
  329.         OSType    aMediaType;
  330.         
  331.         aTrack = GetMovieIndTrack(theMovie, index); DebugAssert(aTrack != NULL);
  332.         aMedia = GetTrackMedia(aTrack); DebugAssert(aMedia != NULL);
  333.         anErr = GetMoviesError(); DebugAssert(anErr == noErr);
  334.         if(anErr != noErr)
  335.         {
  336.             printf("Problems with getting trackmedia = %d\n", anErr);
  337.             return;
  338.         }
  339.         
  340.         GetMediaHandlerDescription(aMedia, &aMediaType, 0, 0);
  341.         if(aMediaType == SoundMediaType)        // We just want to check out the sound description handles.
  342.         {
  343.             SampleDescriptionHandle aDesc = NULL;
  344.             aDesc = (SampleDescriptionHandle)NewHandle(sizeof(SampleDescription)); 
  345.             DebugAssert(GetMemErr() == noErr);
  346.         
  347.             GetMediaSampleDescription(aMedia, 1, aDesc);
  348.             anErr = GetMoviesError(); DebugAssert(anErr == noErr);
  349.             MoveHHi((Handle)aDesc); HLock((Handle)aDesc); // Really would not need to, but printf (don't trust that one
  350.                                                                                      // due to the MetroWerks Sioux environment).
  351.             if(anErr != noErr)
  352.             {
  353.                 DisposeHandle((Handle)aDesc);
  354.                 continue;
  355.             }
  356.             // OK, we have the sound description handle now, present the values
  357.             printf("The sound track rate is %d Hz.\n", (*(SoundDescriptionHandle)aDesc)->sampleRate >> 16);
  358.             {
  359.             long soundRate =  (*(SoundDescriptionHandle)aDesc)->sampleRate >> 16;
  360.             if (soundRate < 30000)
  361.                 if( (soundRate != 22050) && (soundRate != 11025) ) 
  362.                     printf("NOTE! The movie has a sound rate that will maybe cause performance problems with certain PC sound boards. If possible use 22050 or 11025 kHz instead\n");
  363.             }
  364.             
  365.             printf("The sound track size is %d bit.\n", (*(SoundDescriptionHandle)aDesc)->sampleSize);
  366.             
  367.             printf("The sound track has %d channel(s).\n", (*(SoundDescriptionHandle)aDesc)->numChannels);
  368.             {
  369.                 Byte *bp = (Byte *)&(*(SoundDescriptionHandle)aDesc)->dataFormat;
  370.                 printf("The sound track has the '%c%c%c%c' format.\n", bp[0], bp[1], bp[2], bp[3]);
  371.             }
  372.             
  373.             printf("The sound description structure is %ld bytes in size.\n", 
  374.                             (*(SoundDescriptionHandle)aDesc)->descSize);
  375.         }
  376.     }
  377. }
  378.  
  379.  
  380. // ______________________________________________________________________
  381. // This is a variation function of the QTUCountMediaSamples one, we want to figure out how
  382. // many key frames we have in the movie.
  383.  
  384. pascal long QTUCountKeySamples(Movie theMovie, OSType theMediaType)
  385. {
  386.     long numFrames = 0;
  387.     
  388.     short flags = nextTimeEdgeOK + nextTimeSyncSample;
  389.     TimeValue aDuration = 0;
  390.     TimeValue theTime = 0;
  391.     
  392.     GetMovieNextInterestingTime(theMovie, flags, 1, &theMediaType, theTime, 0, &theTime, &aDuration);
  393.     if(theTime == -1) return numFrames;
  394.  
  395.     flags = nextTimeSyncSample; // Don't include the  nudge after the first interesting time.
  396.     
  397.     while(theTime != -1)  // When the returned time equals -1, then there were no more interesting times.
  398.     {
  399.         numFrames++;
  400.         GetMovieNextInterestingTime(theMovie, flags, 1, &theMediaType, theTime, 0, &theTime, &aDuration);
  401.     }
  402.     
  403.     return numFrames;
  404. }
  405.